//
//  AppInfoView.m
//  05-应用管理
//
//  Created by wangneihan on 15/12/14.
//  Copyright © 2015年 wangneihan. All rights reserved.
//

#import "AppInfoView.h"

@implementation AppInfoView

-(void)setAppInfo:(AppInfo *)appInfo{
    
    _appInfo = appInfo;
    
    self.icon.image = [UIImage imageNamed:appInfo.icon];
    self.appName.text = appInfo.name;
    
}

+(instancetype)appInfoView{
    
    NSBundle *bundle = [NSBundle mainBundle];
    
    AppInfoView *appInfoView = [[bundle loadNibNamed:@"AppInfoView" owner:nil options:nil] lastObject];
    
    return appInfoView;
    
}

-(IBAction)downClick:(UIButton *)sender{
    //取消和用户的交互，使view内的所有按钮都不能点击
    self.superview.userInteractionEnabled = NO;
    
    sender.enabled = NO;
    
    UILabel *label = [[UILabel alloc] init];
    
    CGFloat tipH = 40;
    CGFloat tipW = 300;
    CGFloat tipX = (self.superview.frame.size.width - tipW) / 2;
    CGFloat tipY = self.superview.frame.size.height - tipH*2;
    
    label.frame = CGRectMake(tipX, tipY, tipW, tipH);
    label.textAlignment = NSTextAlignmentCenter;
    
    label.text = [NSString stringWithFormat:@"正在下载：%@",self.appInfo.name];
    label.backgroundColor = [UIColor grayColor];
    
    label.alpha = 0;
    
    label.layer.cornerRadius = 5;
    label.layer.masksToBounds = YES;
    
    [UIView animateWithDuration:1.0 animations:^{
        label.alpha = 0.9;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1.0 delay:3.0 options:UIViewAnimationOptionCurveLinear animations:^{
            label.alpha = 0;
            
        } completion:^(BOOL finished) {
            //从父view中移除
            [label removeFromSuperview];
            //
            self.superview.userInteractionEnabled = YES;
        }];
    }];
    
    [self.superview addSubview:label];
    
}

@end
